package service;

import java.sql.Connection;
import java.sql.SQLException;

import messageControl.Message;
import messageControl.MessageDao;
import util.mysqlUtil;

public class WriteMessage {
	
	String tableName;
	public WriteMessage(String tableName){
		this.tableName = tableName;
	}

	public void write(Message message) throws ServiceException {
		Connection conn = null;
		try {
			conn = mysqlUtil.getConn();
			MessageDao messageDao = new MessageDao(tableName);
			messageDao.insert(conn, message);
		} catch (SQLException e) {
			throw new ServiceException(
					"메시지 등록 실패: " + e.getMessage(), e);
		} finally {
			mysqlUtil.close(conn);
		}
	}

}